// pages/order/order.js
Page({
 
    /**
     * 页面的初始数据
     */
    data: {
      currtab: 0,
      swipertab: [{ name: '已完成', index: 0 }, { name: '待付款', index: 1 }, { name: '已取消', index: 2 }],
    },
   
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
   
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
      // 页面渲染完成
      this.getDeviceInfo()
      this.orderShow()
    },
   
    getDeviceInfo: function () {
      let that = this
      wx.getSystemInfo({
        success: function (res) {
          that.setData({
            deviceW: res.windowWidth,
            deviceH: res.windowHeight
          })
        }
      })
    },
   
    /**
    * @Explain：选项卡点击切换
    */
    tabSwitch: function (e) {
      var that = this
      if (this.data.currtab === e.target.dataset.current) {
        return false
      } else {
        that.setData({
          currtab: e.target.dataset.current
        })
      }
    },
   
    tabChange: function (e) {
      this.setData({ currtab: e.detail.current })
      this.orderShow()
    },
   
    orderShow: function () {
      let that = this
      switch (this.data.currtab) {
        case 0:
          that.alreadyShow()
          break
        case 1:
          that.waitPayShow()
          break
        case 2:
          that.lostShow()
          break
      }
    },
    alreadyShow: function(){
      this.setData({
        alreadyOrder: [{ id:1,name: "可口可乐",price:5, state: "交易成功", time: "2018-09-30 14:00", buynum: 3, url: "../../images/index/index1.png", money: 132 }, { id:2,name: "芋泥啵啵奶茶", price:20,state: "交易成功", time: "2018-10-12 18:00", buynum: 5, url: "../../images/index/index1.png", money: "205" }]
      })
    },
   
    waitPayShow:function(){
      this.setData({
        waitPayOrder: [{ id:3,name: "玉溪",price:6, state: "待付款", time: "2018-10-14 16:00", buynum: 2, url: "../../images/index/index1.png", money: 186 }],
      })
    },
   
    lostShow: function () {
      this.setData({
        lostOrder: [{ id:4,name: "青椒肉丝盖饭", price:15,state: "已取消", time: "2018-10-4 10:00", buynum: 1, url: "../../images/index/index1.png", money: 122 }],
      })
    },
    // 删除订单记录
   delete(options){
      console.log(options.target.dataset.id);
   },
    submit(id){
      console.log(id);
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
   
    },
   
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {
   
    },
   
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {
   
    },
   
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
   
    },
   
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
   
    },
   
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
   
    }
  })